<template>
	<c-base-page :current="1" :navText="'工单'">
		<view class="nav-tabs" :style="navbarTopStyle">
			<view class="item" :class="tabIndex==0 ? 'active' : ''" @click="onNavTap(0)">
				全部
			</view>
			<view class="item" :class="tabIndex==1 ? 'active' : ''" @click="onNavTap(1)">
				进行中
			</view>
			<view class="item" :class="tabIndex==2 ? 'active' : ''" @click="onNavTap(2)">
				已完成
			</view>
		</view>
		<view class="order-items">
			<uni-card class="order-card" v-for="item in tableData" @click="toDetail(item)">
				<view class="order-item">
					<text class="title">标&nbsp;&nbsp;&nbsp;&nbsp;题:</text> {{ item.title }}
				</view>
				<view class="order-item">
					<text class="title">时&nbsp;&nbsp;&nbsp;&nbsp;间:</text> {{ item.time }}
				</view>
				<view class="order-item">
					<text class="title">负责人:</text> {{ item.principal }}
				</view>
				<view class="order-btn" v-if="item.status === 1" @click.stop="_complete(item)">
					去处理
				</view>
			</uni-card>
			<!--<uni-load-more :status="loadStatus"></uni-load-more>-->
		</view>
	</c-base-page>
</template>

<script>
	import moment from "moment"
	export default {
		data() {
			return {
				tabIndex: 0,
				listQuery: {
					page: 1,
					pageSize: 10
				},
				tableData: [],
				loadStatus: "more",
				isLoadMore: false,
				navbarTopStyle: ""
			}
		},
		onLoad() {
			this.getNavtabsTopClass();
			this.getDataList();
		},
		methods: {
			getNavtabsTopClass() {
				let h = this.mxNavbarHeight()
				this.navbarTopStyle = {
					top: `${h}px`
				}
			},
			onNavTap(index) {
				this.tabIndex = index || 0;
				this.tableData = [];
				this.getDataList();
			},
			getDataList() {
				this.httpGet({
					url: this.$apis.apiGetWorkOrders
				}).then(res => {
					this.tableData = res
					if (this.tabIndex) {
						this.tableData = this.tableData.filter(x => {
							return x.status === this.tabIndex
						})
					}
					this.tableData = this.tableData.map(x => {
						x.time = moment(x.time).format("YYYY-MM-DD HH:mm:ss")
						return x
					})
				})
			},
			toDetail(row) {
				this.mxNavigateTo(`/pages/work/detail?id=` + row.id)
			},
			_complete(row) {
				let that = this
				uni.showModal({
					title: '提示',
					content: `您确定处理完成吗?`,
					confirmText: '确认',
					success: function(res) {
						if (res.confirm) {
							that.httpPost({
								url: `${that.$apis.apiGetWorkOrders}/${row.id}/complete`
							}).then(res => {
								that.getDataList()
								that.mxToast("已处理完成!")
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.nav-tabs {
		width: 100%;
		height: 88rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		text-align: center;
		position: fixed;
		z-index: 100;
		// top: calc(var(--status-bar-height) + 44px);
		background: $uni-bg-color;
		.item {
			flex: 1;
			font-size: 36rpx;
			color: #999;
		}
		.item.active {
			font-weight: bold;
			color: #55aaff;
		}
	}
	.order-items {
		padding: 88rpx 0 50rpx;
		.order-titles {
			display: flex;
			padding: 20rpx 10px 0;
			align-items: center;
			justify-content: space-between;
			.order-title {
				flex: 1.5;
				font-size: $uni-font-size-base;
				font-weight: bold;
			}
			.order-title.active {
				color: #55aaff;
			}
			.order-extra {
				flex: 1;
				text-align: right;
				color: #999;
			}
		}
		.order-card {
			position: relative;
		}
		.order-item {
			display: flex;
			.title {
				min-width: 4rem;
				margin-right: 6px;
				color: #999;
			}
			.info {
				flex: 1;
				color: #55aaff;
				display: inline-block;
			}
		}
		.order-item.order-bottoms {
			display: flex;
			justify-content: space-between;
			margin-top: 15rpx;
			border-top: 1px solid #eeeeee;
		}
		.order-bottom {
			height: 40rpx;
			padding-top: 10rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.icon {
				width: 25rpx;
				height: 25rpx;
				margin-right: 9rpx;
				border-radius: 50%;
			}
			.time {
				color: #000;
				font-size: $uni-font-size-lg;
				font-weight: bold;
			}
		}
		.order-btn {
			position: absolute;
			padding: 4rpx 10rpx;
			background: #d7fff9;
			border-radius: 6rpx;
			bottom: 20rpx;
			right: 20rpx;
			color: #55aa00;
			font-size: 12px;
		}
	}
</style>
